//    Copyright (C) Kherty.  All rights reserved.
using System;
using OpenLS.Core.Serialization;
using OpenLS.Spreadsheet.Data;

namespace OpenLS.Spreadsheet.Pivot
{
    internal abstract class PivotTableValue : IOfficeXmlSerializable
    {
        internal static PivotTableValue Read(ReadContext c)
        {
            PivotTableValue result = create(c);
            result.ReadXml(c);
            return result;
        }

        private static PivotTableValue create(ReadContext context)
        {
            switch (context.ReaderLocalName)
            {
                case PivotTableError.xmlName: return new PivotTableError();
                case PivotTableBoolean.xmlName: return new PivotTableBoolean();
                case PivotTableDateTime.xmlName: return new PivotTableDateTime();
                case PivotTableMissing.xmlName: return new PivotTableMissing();
                case PivotTableNumber.xmlName: return new PivotTableNumber();
                case PivotTableString.xmlName: return new PivotTableString();
                case Index.xmlName: return new Index();
                default: throw new NotSupportedException(context.ReaderLocalName);
            }
        }

        public abstract void ReadXml(ReadContext context);
        public abstract void WriteXml(WriteContext context);
        public abstract object Value { get; }
    }
}